package com.inheritance.controller;

import com.inheritance.common.Result;
import com.inheritance.entity.Notice;
import com.inheritance.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    // 新增公告
    @PostMapping("/upload")
    public Result<?> upload(@RequestBody Notice notice) {
        int i = noticeService.upload(notice);
        if (i > 0) {
            return Result.success("新增成功");
        }
        return Result.error("新增失败");
    }

    // 获取公告列表
    @GetMapping("/list")
    public Result<?> list() {
        return Result.success("查询成功", noticeService.list());
    }

    // 删除公告
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable String id) {
        Boolean ok = noticeService.delete(id);
        if (ok) {
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

}
